<template>
  <div>
    <Topinput :isShow="true" @serve="serveFn"></Topinput>
    <Toptable :tabHeader="tabHeader" :list="list" :loading.sync="loading" @newForm="newForm">
      <template #operation="{row}">
        <el-button @click="workRow(row)" type="text" size="small">查看详情</el-button>
      </template>
    </Toptable>
    <div class="left">
      <span>共{{total}}条记录 第 {{this.params.pageIndex}} / {{totalPage}}</span>
    </div>
    <div class="right">
      <el-button-group>
        <el-button
          type="primary"
          icon="el-icon-arrow-left"
          layout="prev, pager, next"
          :total="total"
          @click="add(1)"
          :disabled="params.pageIndex===1"
        >上一页</el-button>
        <el-button
          background
          type="primary"
          @click="add(2)"
          :disabled="params.pageIndex===totalPage"
        >
          下一页
          <i class="el-icon-arrow-right el-icon--right"></i>
        </el-button>
      </el-button-group>
    </div>

    <viewDetails ref="viewDetails" :row='row'></viewDetails>
  </div>
</template>

<script>
import Topinput from '@/views/user/childrens/components/input'
import Toptable from '@/views/user/childrens/components/table'
import { searchUserWork } from '@/api/kuser'
import viewDetails from '@/views/user/childrens/components/viewDetails.vue'
export default {
  name: 'Dkd3Type',

  components: {
    Topinput,
    Toptable,
    viewDetails
  },

  data () {
    return {
      params: {
        pageIndex: 1,
        pageSize: 10,
        userName: '',
        roleld: '',
        regionName: ''
      },
      loading: false,
      list: [],
      totalPage: 0,
      total: 0,
      tabHeader: {
        userName: '人员名称',
        roleName: '角色',
        mobile: '联系电话',
        workCount: '进行中工单',
        progressTotal: '完成工单（本月）',
        total: '拒绝工单（本月）'
      },
      row: {}
    }
  },

  created () {
    this.searchUserWork()
  },

  methods: {
    async searchUserWork () {
      const res = await searchUserWork(this.params)
      console.log(res)
      this.list = res.currentPageRecords
      this.totalPage = res.totalPage

      this.total = res.totalCount
      this.loading = false
    },
    newForm (val) {
      this.$refs.addForm.visible = val
    },
    // 搜素
    serveFn (val, val1) {
      this.params.userName = val
      this.params.roleName = val1
      console.log(val, val1)
      this.searchUserWork()
    },
    // 分液器
    add (val) {
      if (val === 1) {
        this.params.pageIndex -= 1
        if (this.params.pageIndex === 0) {
          this.params.pageIndex = 1
        }
      } else {
        this.params.pageIndex += 1
        if (this.params.pageIndex >= this.totalPage) {
          this.params.pageIndex = this.totalPage
        }
      }
      // val === 1 ? (this.params.pageIndex -= 1) : (this.params.pageIndex += 1)
      this.searchUserWork()
    },
    workRow (row) {
      console.log(row)
      this.row = row
      this.$refs.viewDetails.visible = true
    }
  }
}
</script>

<style lang="less" scoped>
.left {
  margin-top: 20px;
  float: left;
  span {
    color: #ccc;
    font-size: 16px;
  }
}
.right {
  margin-top: 20px;
  float: right;
}
</style>
